import { DialogConfig } from '@/components/mm-dialog/type'

export const dialogConfig: DialogConfig = {
  width: 620,
  showLabel: true,
  labelWidth: 95,
  layout: [
    {
      gutter: 20,
      formItems: [
        {
          label: '运营商',
          prop: 'isp_id',
          type: 'select',
          placeholder: '请选择运营商',
          optionsGetter: 'icafe/ispOptions',
          rules: [{ required: true, message: '必填项不能为空', trigger: 'change' }]
        },
        {
          label: '带宽(Mbps)',
          prop: 'bandwidth',
          type: 'number',
          placeholder: '请输入带宽',
          default: 0,
          bind: {
            min: 0,
            controlsPosition: 'right'
          },
          rules: [{ required: true, message: '必填项不能为空', trigger: 'blur' }]
        }
      ]
    },
    {
      gutter: 20,
      formItems: [
        {
          label: 'IP地址',
          prop: 'ip',
          type: 'input',
          placeholder: '请输入IP地址',
          rules: [
            { required: true, message: '必填项不能为空', trigger: 'blur' },
            {
              pattern: /^((2(5[0-5]|[0-4]\d))|1\d{2}|[1-9]?\d)(\.((2(5[0-5]|[0-4]\d))|1\d{2}|[1-9]?\d)){3}$/,
              message: '格式不正确',
              trigger: 'blur'
            }
          ]
        }
      ]
    },
    {
      gutter: 20,
      formItems: [
        {
          label: '子网掩码',
          prop: 'mask',
          type: 'input',
          placeholder: '请输入子网掩码',
          rules: [
            { required: true, message: '必填项不能为空', trigger: 'blur' },
            {
              pattern: /^((2(5[0-5]|[0-4]\d))|1\d{2}|[1-9]?\d)(\.((2(5[0-5]|[0-4]\d))|1\d{2}|[1-9]?\d)){3}$/,
              message: '格式不正确',
              trigger: 'blur'
            }
          ]
        },
        {
          label: '网关',
          prop: 'gateway',
          type: 'input',
          placeholder: '请输入网关',
          rules: [
            { required: true, message: '必填项不能为空', trigger: 'blur' },
            {
              pattern: /^((2(5[0-5]|[0-4]\d))|1\d{2}|[1-9]?\d)(\.((2(5[0-5]|[0-4]\d))|1\d{2}|[1-9]?\d)){3}$/,
              message: '格式不正确',
              trigger: 'blur'
            }
          ]
        }
      ]
    },
    {
      gutter: 20,
      formItems: [
        {
          label: '访问协议',
          prop: 'protocol',
          type: 'select',
          placeholder: '请选择访问协议',
          options: [
            { label: 'http://', value: 'http://' },
            { label: 'https://', value: 'https://' }
          ],
          rules: [{ required: true, message: '必填项不能为空', trigger: 'change' }]
        },
        {
          label: '访问端口',
          prop: 'port',
          type: 'input',
          placeholder: '请输入访问端口',
          rules: [
            { required: true, message: '必填项不能为空', trigger: 'blur' },
            {
              validator: (rule: any, value: string, callback: CallableFunction) => {
                if (parseInt(value) > 0 && parseInt(value) < 65536) {
                  callback()
                } else {
                  callback(new Error('必须为 1 - 65535 之间的整数'))
                }
              },
              trigger: 'blur'
            }
          ]
        }
      ]
    },
    {
      formItems: [
        {
          label: '备注',
          prop: 'remarks',
          type: 'textarea',
          placeholder: '请输入备注',
          bind: {
            rows: 3
          }
        }
      ]
    }
  ]
}
